package com.panopset.sf.menu;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

import javax.swing.JMenu;

import com.panopset.compat.Strings;
import com.panopset.nls.MsgProps;
import com.panopset.sf.Windoc;

/**
 * File menu.
 * 
 * @author Karl Dinwiddie
 * 
 */
public class FileMenu extends AbstractMenu {

	/**
	 * 
	 * @param swingDoc
	 *            SwingDoc.
	 */
	public FileMenu(final Windoc swingDoc) {
		super(swingDoc, Strings.capitalize(new MsgProps(
				Windoc.SD_MSG_PROPS).get("file")));
	}

	/**
	 * 
	 * @return File menu.
	 */
	protected void populateMenu(JMenu menu) {
		menu.add(createMenuItem(Windoc.SD_MSG_PROPS, "new",
				new ActionListener() {
					public void actionPerformed(final ActionEvent e) {
						sd.sf.doNew();
					}
				}));
		menu.add(createMenuItem(Windoc.SD_MSG_PROPS, "open",
				new ActionListener() {
					public void actionPerformed(final ActionEvent e) {
						sd.doOpen();
					}
				}));
		menu.addSeparator();
		menu.add(createMenuItem(Windoc.SD_MSG_PROPS, "save",
				new ActionListener() {
					public void actionPerformed(final ActionEvent e) {
						sd.save();
					}
				}));
		menu.add(createMenuItem(Windoc.SD_MSG_PROPS, "savas",
				new ActionListener() {
					public void actionPerformed(final ActionEvent e) {
						sd.saveas();
					}
				}));
		menu.addSeparator();
		menu.add(createMenuItem(Windoc.SD_MSG_PROPS, "close",
				new ActionListener() {
					public void actionPerformed(final ActionEvent e) {
						sd.closeCheckForExit();
					}
				}, KeyEvent.VK_W));
		menu.addSeparator();
		menu.add(createMenuItem(Windoc.SD_MSG_PROPS, "reset",
				new ActionListener() {
					public void actionPerformed(final ActionEvent e) {
						sd.reset();
					}
				}));
		menu.add(createMenuItem(Windoc.SD_MSG_PROPS, "exit",
				new ActionListener() {
					public void actionPerformed(final ActionEvent e) {
						sd.sf.userCommandExit();
					}
				}, KeyEvent.VK_X));
	}
}
